/*
 * @Author: HeAo
 * @Date: 2021-09-30 14:06:41
 * @LastEditTime: 2021-09-30 14:23:27
 * @LastEditors: HeAo
 * @Description:
 * @FilePath: \web2103-2105\web2105\3-1-ES6\day06\1-迭代器.js
 * 别乱动！
 */

// String.prototype[Symbol.iterator] = function() {

// }
// String.prototype = {
//   [Symbol.iterator]: function () {

//   }
// }

// 自带iterator接口的数据，别成为可迭代数据
// 其原型对象上，内置了iterator接口，该接口是个函数，返回值就是实例对应的迭代器对象
// let itear = 'hello'[Symbol.iterator]()
// console.log(itear);
// console.log(itear.next());
// console.log(itear.next());
// console.log(itear.next());
// console.log(itear.next());
// console.log(itear.next());
// console.log(itear.next());

let obj1 = {
  name: 'zhangsan',
  age: 12,
  gender: 'male'
}
Object.prototype[Symbol.iterator] = function* () {
  for (let k in this) {
    yield [k, this[k]]
  }
}

for (let entry of obj1) {
  console.log(entry);
}

